package com.sgb.kjwl.view.ui.adapter.self.logistics;

import android.annotation.SuppressLint;
import android.content.Context;
import android.text.TextUtils;

import com.sgb.kjwl.BR;
import com.sgb.kjwl.R;
import com.sgb.kjwl.databinding.ItemBiddingOrderBinding;
import com.sgb.kjwl.model.entity.self.BiddingOrderEntity;
import com.sgb.kjwl.utils.CargoConstant;
import com.sgb.kjwl.utils.NumberUtil;
import com.swgk.core.recyclerview.adapter.BaseRecycleAdapter;
import com.swgk.core.recyclerview.adapter.ItemViewHolder;

import java.util.List;

/**
 * Time:2021/7/15
 * Author:黄淋
 * Description:竞价订单 适配器
 */
public class BiddingOrderAdapter extends BaseRecycleAdapter<BiddingOrderEntity> {
    private boolean mIsGoodsOwner;

    public BiddingOrderAdapter(Context context, List<BiddingOrderEntity> datas, boolean isGoodsOwner) {
        super(context, R.layout.item_bidding_order, datas);
        this.mIsGoodsOwner = isGoodsOwner;
    }

    @SuppressLint("SetTextI18n")
    @Override
    public void convert(ItemViewHolder holder, BiddingOrderEntity biddingOrderEntity) {
        holder.setBinding(BR.viewModel, biddingOrderEntity);
        ItemBiddingOrderBinding binding = (ItemBiddingOrderBinding) holder.getmBinding();
        if (mIsGoodsOwner) {
            binding.tvTitleCompanyName.setText("承运单位：" + (TextUtils.isEmpty(biddingOrderEntity.getUnitName()) ? "/" : biddingOrderEntity.getUnitName()));
        } else {
            binding.tvTitleCompanyName.setText("发货单位：" + (TextUtils.isEmpty(biddingOrderEntity.getUnitName()) ? "/" : biddingOrderEntity.getUnitName()));
        }

        //货物详情
        String goodsInfo = "";
            goodsInfo += CargoConstant.getLastGoodsTypeName(biddingOrderEntity.getGoodsTypeName(),biddingOrderEntity.getSecondGoodsTypeName());
        if (!TextUtils.isEmpty(biddingOrderEntity.getWeight())) {
            goodsInfo += "/" + NumberUtil.trim0(biddingOrderEntity.getWeight()) + "吨";
        }
        if (!TextUtils.isEmpty(biddingOrderEntity.getVolume())) {
            goodsInfo += "/" + NumberUtil.trim0(biddingOrderEntity.getVolume()) + "方";
        }
        binding.offerGoods.setText(TextUtils.isEmpty(goodsInfo) ? "/" : goodsInfo);

        //装货时间
        binding.offerGoodsTime.setText(CargoConstant.stampFormatListLoadTime(true,
                biddingOrderEntity.getShipmentTime(), biddingOrderEntity.getStartPointTime(),
                biddingOrderEntity.getShipmentEndTime(), biddingOrderEntity.getEndPointTime()));

        //运费单价
        if (biddingOrderEntity.getFreight() == null) {
            binding.newestFreightOffer.setText("/");
        } else {
            binding.newestFreightOffer.setText(String.format("%s%s", NumberUtil.trim0(biddingOrderEntity.getFreight().floatValue()), "元/吨"));
        }
    }
}
